package cn.demo.cm.controller;

import cn.demo.cm.domain.CmCategory;
import cn.demo.cm.service.ICmCategoryService;
import cn.demo.common.annotation.Log;
import cn.demo.common.core.controller.BaseController;
import cn.demo.common.core.domain.R;
import cn.demo.common.enums.BusinessType;
import cn.demo.common.utils.poi.ExcelUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 栏目管理Controller
 *
 * @author xtjun
 * @date 2024-06-04
 */
@Tag(name = "栏目管理")
@RestController
@RequestMapping("/cm/cmCategory")
public class CmCategoryController extends BaseController {
    @Resource
    private ICmCategoryService cmCategoryService;

    @Operation(summary = "查询栏目管理列表")
    @PreAuthorize("@ss.hasPermi('cm:cmCategory:list')")
    @GetMapping("/list")
    public R<List<CmCategory>> list(CmCategory cmCategory) {
        List<CmCategory> list = cmCategoryService.selectCmCategoryList(cmCategory);
        return R.ok(list);
    }

    @Operation(summary = "导出栏目管理列表")
    @PreAuthorize("@ss.hasPermi('cm:cmCategory:export')")
    @Log(title = "栏目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmCategory cmCategory) {
        List<CmCategory> list = cmCategoryService.selectCmCategoryList(cmCategory);
        ExcelUtil<CmCategory> util = new ExcelUtil<CmCategory>(CmCategory.class);
        util.exportExcel(response, list, "栏目管理数据");
    }

    @Operation(summary = "获取栏目管理详细信息")
    @PreAuthorize("@ss.hasPermi('cm:cmCategory:query')")
    @GetMapping(value = "/{id}")
    public R<CmCategory> getInfo(@PathVariable("id") String id) {
        return R.ok(cmCategoryService.selectCmCategoryById(id));
    }

    @Operation(summary = "新增栏目管理")
    @PreAuthorize("@ss.hasPermi('cm:cmCategory:add')")
    @Log(title = "栏目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody CmCategory cmCategory) {
        return toAjax(cmCategoryService.insertCmCategory(cmCategory));
    }

    @Operation(summary = "修改栏目管理")
    @PreAuthorize("@ss.hasPermi('cm:cmCategory:edit')")
    @Log(title = "栏目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody CmCategory cmCategory) {
        return toAjax(cmCategoryService.updateCmCategory(cmCategory));
    }

    @Operation(summary = "删除栏目管理")
    @PreAuthorize("@ss.hasPermi('cm:cmCategory:remove')")
    @Log(title = "栏目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable List<String> ids) {
        return toAjax(cmCategoryService.deleteCmCategoryByIds(ids));
    }
}
